//
//  ErrorHistoryTableCell.m
//  GoldOperationClient
//
//  Created by yaxue wang on 16/8/9.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "ErrorHistoryTableCell.h"
#import "ErrorHistoryModel.h"
@interface ErrorHistoryTableCell()
@property (nonatomic, strong) UIView *coverView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *contexLab;
@property (nonatomic, strong) UILabel *clientLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UIImageView *stateImg;
@property (nonatomic, strong) UILabel *stateLab;
@property (nonatomic, strong) UILabel *line;
@end
@implementation ErrorHistoryTableCell
- (void)initView{
    [super initView];
    self.backgroundColor =[UIColor clearColor];
    
    self.coverView =[[UIView alloc]initWithFrame:CGRectMake(25, 0, WindowWidth-50, 145)];
    [self addSubview:self.coverView];
    self.coverView.backgroundColor =[UIColor whiteColor];
    self.coverView.layer.masksToBounds =YES;
    self.coverView.layer.cornerRadius =7;
    
    
    
    self.stateLab = [[UILabel alloc] init];
    [self.coverView addSubview:self.stateLab];
    [self.stateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.coverView).offset(-15);
        make.top.equalTo(self.coverView).offset(10);
        make.width.equalTo(@(40));
        make.height.equalTo(@(20));
        
    }];
    self.stateLab.textColor =[UIColor whiteColor];
    self.stateLab.textAlignment=NSTextAlignmentCenter;
    self.stateLab.font =F(10);
    
    self.titleLab =[[UILabel alloc]init];
    [self.coverView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.coverView).offset(15);
        make.top.equalTo(self.coverView).offset(10);
        make.right.equalTo(self.stateLab.mas_left).offset(-5);
    }];
    self.titleLab.textColor = C(@"454545");
    self.titleLab.font = F(11);
    
    
    self.clientLab = [[UILabel alloc]init];
    [self.coverView addSubview:self.clientLab];
    [self.clientLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.top.equalTo(self.titleLab.mas_bottom).offset(10);
        make.right.equalTo(self.coverView).offset(-10);
    }];
    self.clientLab.textColor =C(@"a19d9d");
    self.clientLab.font =F(10);
    
    
    
    self.nameLab = [[UILabel alloc]init];
    [self.coverView addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.top.equalTo(self.clientLab.mas_bottom).offset(10);
        make.right.equalTo(self.coverView).offset(-10);
    }];
    self.nameLab.textColor =C(@"a19d9d");
    self.nameLab.font =F(10);
    
    
    self.contexLab =[[UILabel alloc]init];
    [self.coverView addSubview:self.contexLab];
    [self.contexLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLab);
        make.top.equalTo(self.nameLab.mas_bottom).offset(10);
        make.width.equalTo(self.titleLab);
        
    }];
    self.contexLab.textColor =C(@"a19d9d");
    self.contexLab.font =F(10);
    
    self.line =[[UILabel alloc]init];
    [self.coverView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.coverView).offset(15);
        make.top.equalTo(self.coverView.mas_bottom).offset(-43);
        make.right.equalTo(self.coverView).offset(-15);
        make.height.equalTo(@(0.5));
    }];
    self.line.backgroundColor =C(@"e8e7e7");

    self.stateLab =[[UILabel alloc]init];
    [self.coverView addSubview:self.stateLab];
    [self.stateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.coverView).offset(-18);
        make.bottom.equalTo(self.coverView.mas_bottom).offset(-14);
        make.width.mas_offset(@(48));
    }];
    self.stateLab.font =F(12);
    self.stateImg = [[UIImageView alloc] init];
    [self.coverView addSubview:self.stateImg];
    UIImage *img1 =[UIImage imageNamed:@"Ico_home_canle"];
    [self.stateImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.stateLab.mas_left).offset(-9);
        make.bottom.equalTo(self.coverView.mas_bottom).offset(-14);
        make.size.mas_equalTo(CGSizeMake(img1.size.width, img1.size.height));
    }];
    
    self.timeLab =[[UILabel alloc]init];
    [self.coverView addSubview:self.timeLab];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.coverView).offset(15);
        make.top.equalTo(self.line.mas_bottom).offset(14);
        make.right.equalTo(self.stateImg.mas_left).offset(-5);
    }];
    self.timeLab.font =F(10);
    self.timeLab.textColor =[UIColor colorFromHexString:@"a19d9d"];

   
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    //    [self setBackgroundColor:[UIColor clearColor]];
}
- (void)setModel:(id)model{
    

    
    ErrorHistoryModel *order = model;

    if (order.E_order_number ==nil||[order.E_order_number isEqualToString:@""]) {
        self.titleLab.text =@"报修单号：单号为空";
        
    }else
    {
        self.titleLab.text =[NSString stringWithFormat:@"报修单号：%@",order.E_order_number];
    }
    if (order.E_order_number ==nil||[order.E_order_number isEqualToString:@""]) {
        self.clientLab.text =@"报修客户：";
        
    }else
    {
        
        self.clientLab.text =[NSString stringWithFormat:@"报修客户：%@",order.E_bankname];
    }
    
    if ((order.E_name ==nil||[order.E_name isEqualToString:@""])&&(order.E_type_cd ==nil||[order.E_type_cd isEqualToString:@""])) {
        self.nameLab.text =[NSString stringWithFormat:@"%@%@",order.E_name,order.E_type_cd];
        self.nameLab.hidden=YES;
        
    }else if ((order.E_name ==nil||[order.E_name isEqualToString:@""])||(order.E_type_cd ==nil||[order.E_type_cd isEqualToString:@""])) {
        
        if(order.E_name ==nil||[order.E_name isEqualToString:@""]){
            self.nameLab.text =[NSString stringWithFormat:@"%@",order.E_type_cd];
            self.nameLab.hidden=NO;
        }else{
            self.nameLab.text =[NSString stringWithFormat:@"%@",order.E_name];
            self.nameLab.hidden=NO;
        }
        
    }else
    {
        self.nameLab.hidden=NO;
        self.nameLab.text =[NSString stringWithFormat:@"%@ %@",order.E_type_cd,order.E_name];
    }
    
    if ([order.E_textFlg isEqualToString:@"0"]) {
        self.contexLab.text=@"(非文字报修)";
        
    }else
    {
        self.contexLab.text=order.E_textdescribe;
        
    }
    NSString  *a = order.E_created;
    if (a ==nil||[a isEqualToString:@""]) {
        self.timeLab.text =@"";
        
    }else
    {
      
        self.timeLab.text =a;
    }

    if (order.E_state ==nil||[order.E_state isEqualToString:@""]){
        
        
    }else
    {
        if([order.E_state integerValue] ==97)
        {
            self.stateImg.image =[UIImage imageNamed:@"Ico_home_canle"];
            self.stateLab.textColor =Yellow;
            self.stateLab.text =@"已取消";
        }
        if ([order.E_state integerValue] ==98) {
            
            self.stateImg.image =[UIImage imageNamed:@"Ico_home_ complete"];
            self.stateLab.textColor =[UIColor colorFromHexString:@"29b404"];
            self.stateLab.text =@"待评价";
            
        }
        if ([order.E_state integerValue] ==99) {
            
            self.stateImg.image =[UIImage imageNamed:@"Ico_home_ complete"];
            self.stateLab.textColor =[UIColor colorFromHexString:@"29b404"];
            self.stateLab.text =@"已完成";
            
        }
 
    }
  
    
}
@end
